using System;
using System.Collections.Generic;
using AutoTest.Core.Infrastructure.Messaging;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

namespace AutoTest.Core.Infrastructure.IoC
{
    public class ServiceLocator : IServiceLocator
    {
        private IWindsorContainer _container;

        public void Init()
        {
            _container = new WindsorContainer();
            _container.Register(Component.For<IServiceLocator>().Instance(this).LifeStyle.Singleton);
            _container.RegisterAllTypesImplementing(typeof (IConsumerOf<>), typeof (IInterceptorOf<>));
            _container.RegisterAllTypesWithInterfaceMatchingClassNameExcept(typeof (ServiceLocator));
            Console.Out.Write("");
        }

        public T Get<T>()
        {
            return _container.Resolve<T>();
        }

        public IEnumerable<T> GetAll<T>()
        {
            return _container.ResolveAll<T>();
        }
    }
}